<?php

class StatViewModel extends Model
{

    public function getGlobalStat()
    {
        $globalStat = array();
          
         $pre = C("DB_PREFIX");
        
        //新闻统计
        $sql = "SELECT COUNT(newshash) AS news_cnt,SUM(media) AS media_cnt,SUM(view) AS view_cnt, SUM(comment) AS comment_cnt,SUM(image) AS image_cnt, SUM(doc) AS doc_cnt, SUM(other) AS other_cnt FROM {$pre}news";
        $ret = $this->query($sql);;

        return $ret[0];

    }



        public function getAllSiteStat()
    {
        $siteStat = array();
          
         $pre = C("DB_PREFIX");

        //新闻统计
        $sql = "SELECT COUNT(a.newshash) AS news_cnt,SUM(a.media) AS media_cnt,SUM(a.view) AS view_cnt, SUM(a.comment) AS comment_cnt,SUM(a.image) AS image_cnt, SUM(a.doc) AS doc_cnt, SUM(a.other) AS other_cnt,c.title,c.sitehash FROM {$pre}news AS a, {$pre}category AS b,{$pre}site AS c WHERE a.categoryhash=b.categoryhash AND b.sitehash=c.sitehash GROUP BY b.sitehash";
        $ret = $this->query($sql);

        return $ret;

    }


    public function getStat($name)
    {
         $pre = C("DB_PREFIX");
         $sql = "SELECT * FROM {$pre}stat WHERE name='".$name."'";
         $ret = $this->query($sql);

         return $ret!=false ? $ret[0]['value'] : false;
    }

    public function incStat($name)
    {
         $pre = C("DB_PREFIX");
         $sql = "UPDATE {$pre}stat SET value=value+1 WHERE name='".$name."'";
         
         return $this->query($sql);

    }
}

?>